package cn.com.dcsgo.controller;

import cn.com.dcsgo.model.product.SkuInfo;
import cn.com.dcsgo.result.Result;
import cn.com.dcsgo.service.SkuInfoService;
import cn.com.dcsgo.vo.product.SkuInfoQueryVo;
import cn.com.dcsgo.vo.product.SkuInfoVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/*
接口路径及参数参考前端文件：
uu-preferred-front-end/uuyx-admin/src/api/product/skuInfo.js
 */

/**
 * <p>
 * sku信息 前端控制器
 * </p>
 *
 * @author Dcsgo
 * @since 2025-04-07
 */
@RestController
@Api(tags = "SKU")
@RequiredArgsConstructor
@RequestMapping("/admin/product/skuInfo")
public class SkuInfoController {
    private final SkuInfoService skuInfoService;

    @ApiOperation("分页条件查询SKU信息")
    @GetMapping("{page}/{size}")
    public Result<IPage<SkuInfo>> getPageList(
            @PathVariable Long page,
            @PathVariable Integer size,
            SkuInfoQueryVo skuInfoQueryVo) {
        Page<SkuInfo> pageParma = new Page<>(page, size);
        IPage<SkuInfo> result = skuInfoService.selectByPage(pageParma, skuInfoQueryVo);
        return Result.ok(result);
    }

    @ApiOperation("添加SKU")
    @PostMapping("save")
    public Result<Serializable> save(@RequestBody SkuInfoVo skuInfoVo) {
        skuInfoService.saveSkuInfo(skuInfoVo);
        return Result.ok(null);
    }

    @ApiOperation("根据id查询SKU")
    @GetMapping("get/{id}")
    public Result<SkuInfoVo> getMethodName(@PathVariable Long id) {
        return Result.ok(skuInfoService.getSkuInfoVoById(id));
    }

    @ApiOperation("修改SKU")
    @PutMapping("update")
    public Result<Serializable> updateById(@RequestBody SkuInfoVo skuInfoVo){
        skuInfoService.updateSkuInfoById(skuInfoVo);
        return Result.ok(null);
    }

    @ApiOperation("通过id删除SKU")
    @DeleteMapping("remove/{id}")
    public Result<Serializable> removeById(@PathVariable Long id){
        skuInfoService.removeByIdWithEs(id);
        return Result.ok(null);
    }

    @ApiOperation("通过id批量删除SKU")
    @DeleteMapping("batchRemove")
    public Result<Serializable> batchRemove(@RequestBody List<Long> ids){
        skuInfoService.removeByIdsWithEs(ids);
        return Result.ok(null);
    }

    @ApiOperation("商品上架")
    @GetMapping("publish/{id}/{status}")
    public Result<Serializable> publish(@PathVariable Long id,@PathVariable Integer status){
        skuInfoService.publishById(id,status);
        return Result.ok(null);
    }

    @ApiOperation("商品审核")
    @GetMapping("check/{id}/{status}")
    public Result<Serializable> check(@PathVariable Long id,@PathVariable Integer status){
        skuInfoService.checkById(id,status);
        return Result.ok(null);
    }

    @ApiOperation("新人专项")
    @GetMapping("isNewPerson/{id}/{status}")
    public Result<Serializable> isNewPerson(@PathVariable Long id,@PathVariable Integer status){
        skuInfoService.updateIsNewPersonById(id,status);
        return Result.ok(null);
    }
}
